Passed
Push — task/update-profile-experience ( 897bfe...e35027 )
by Tristan
06:27
created

deepEquals.ts ➔ deepEquals   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
1
import isEqualWith from "lodash/isEqualWith";
2
import isEqual from "lodash/isEqual";
3
4
export function deepEquals(object: any, other: any): boolean {
5
  return isEqual(object, other);
6
}
7
8
/**
9
 * Logs to console any values which are not equal.
10
 * DO NOT USE IN PRODUCTION.
11
 */
12
function deepEqualsDebug(object: any, other: any): boolean {
13
  const debugCompare = (a, b, key) => {
14
    const equality = isEqual(a, b);
15
    if (!equality) {
16
      console.debug(`The values at key/index ${key} were not equal:`, a, b);
17
    }
18
    return equality;
19
  };
20
  if (
21
    typeof object === "object" &&
22
    typeof other === "object" &&
23
    object !== null &&
24
    other !== null
25
  ) {
26
    return (
27
      debugCompare(
28
        Object.keys(object).length,
29
        Object.keys(other).length,
30
        "length",
31
      ) &&
32
      Object.keys(object).every((key) =>
33
        debugCompare(object[key], other[key], key),
34
      )
35
    );
36
  }
37
  return isEqualWith(object, other, debugCompare);
38
}
39
40
export default deepEquals;
41